#coding=utf-8

import urllib2   
  
def login(name,ps):   
    opener=urllib2.build_opener(urllib2.HTTPCookieProcessor())   
    opener.addheaders = [('User-agent', 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; .NET CLR 1.1.4322)')]
    #User-Agent    Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; .NET CLR 1.1.4322)   
    urllib2.install_opener(opener)   
    #01 login   

    data='username=%s&password=%s' % (name,ps)   
    req = urllib2.Request(url='https://passport.baidu.com/?login',data=data)   
    f = urllib2.urlopen(req)
    print "login..."  
    assert 200 == f.code
    print f.read()
    
    req = urllib2.Request(url='http://hi.baidu.com/sanjiely/blog')   
    f = urllib2.urlopen(req)
    assert 200 == f.code   
    response =  f.read()
    #print response
       
       
def login2(name, ps):
    print name       
       
if __name__ == '__main__':   
       
    login(u"牛头人德鲁伊", '')  